<article class="module width_full">
    <header>
        <h3 class="tabs_involved">优惠券列表</h3>
        <ul class="tabs">
            <form action='{url:/sellercoupon/coupon_list}' method='get'>
                <input type='hidden' name='controller' value='sellercoupon'/>
                <input type='hidden' name='action' value='coupon_list'/>
                <li class="operating">
                    <div class="search f_l">
                        优惠券名称：<input type='text' name='coupon_name' id="coupon_name" value="{$coupon_name}"/>
                        &nbsp;
                        &nbsp;
                        <button class="btn"><span>查 询</span></button>
                    </div>
                </li>
                <li><input type="button" class="alt_btn" onclick="window.location.href='{url:/sellercoupon/create_coupon}';" value="添加优惠券"/></li>
            </form>
        </ul>
    </header>
    <form action="{url:/seller/ship_info_del}" method="post" name="ship_list">
        <table class="tablesorter" cellspacing="0">
            <thead>
            <tr>
                <th>优惠券名称</th>
                <th>优惠额度</th>
                <th>有效期</th>
                <th>总数量</th>
                <th>未发放</th>
                <th>未使用</th>
                <th>已使用</th>
                <th>已失效</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {set:$page= (isset($_GET['page'])&&(intval($_GET['page'])>0))?intval($_GET['page']):1;}
            {set:$seller_id = $this->seller['seller_id']}
            {foreach:items = $this->couponHandle->find()}
            <tr>
                <td> {$item['name']}</td>
                <td> {if:$item['discount_money']>0}{$item['discount_money']}元{else:}{$item['discount_point']}积分{/if}</td>
                <td> {$item['start_time']} ～ {$item['end_time']}</td>
                <td> {if:$item['prop_sale']==1}不限制{else:}{if:$item['goods_sale_num']}{$item['goods_sale_num']}{else:}0{/if}{/if}</td>
                <td>{if:$item['prop_sale']==1}/{else:}{if:$un_send[$item['id']]['count']}{$un_send[$item['id']]['count']}{else:}0{/if}{/if}</td>
                <td>{if:$un_use&&$un_use[$item['id']]}{$un_use[$item['id']]['count']}{else:}0{/if}</td>
                <td>{if:$has_use&&$has_use[$item['id']]}{$has_use[$item['id']]['count']}{else:}0{/if}</td>
                <td>{if:$out_data&&$out_data[$item['id']]}{$out_data[$item['id']]['count']}{else:}0{/if}</td>
                <td>
                    <a href="{url:/sellercoupon/coupon_edit/id/$item['id']}">查看</a>
                    <a href="{url:/sellercoupon/coupon_detail/id/$item['id']}">发放详情 </a>
                    <a href="#" onclick="stop({$item['id']});" >强制结束</a>
                </td>
            </tr>
            {/foreach}

            </tbody>
        </table>
    </form>
    {$this->couponHandle->getPageBar()}
</article>
<script>
    function stop(coupon_id)
    {
        if (coupon_id) {
            var url = '{url:/sellercoupon/finish_message_view/coupon_id/@coupon_id@}';
            url = url.replace("@coupon_id@", coupon_id);
            art.dialog.open(url, {
                id: 'addSpecWin',
                title: '消息',
                okVal: '强制结束',
                cancel: '暂不结束',
                ok: function (iframeWin, topWin) {
                    var formObject = iframeWin.document.forms['coupon_finish'];
                    var me = this;
                    $.post(formObject.action,$(formObject).serialize(), function (json) {
                        if (json.flag == 'success') {
                            window.location.reload();
                            me.close();
                            return true;
                        }
                        else {
                            alert(json.message);
                            return false;
                        }
                    }, 'json');
                    return false;
                }
            });
        }

    }
</script>